package mo.leetcode_hot;

public class L169 {

    public int majorityElement(int[] nums) {
        int count = 0;
        Integer candidate = null;
        for (int num : nums) {
            if (count == 0) {
                candidate = num;
            }
            count = candidate == num ? count + 1 : count - 1;
        }
        return candidate;
    }

    public static void main(String[] args) {
        L169 test = new L169();
        System.out.println(test.majorityElement(new int[]{2,2,1,1,1,2,2}));
    }
}
